package com.ruoyi.web.controller.food;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.entity.Result;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.GrainsituationRecordDetail;
import com.ruoyi.system.domain.SectorDTO;
import com.ruoyi.system.service.IGrainsituationRecordDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 粮情主下的详情Controller
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/web/record/detail")
@Api(tags = "粮情主下的详情")
public class GrainsituationRecordDetailController extends BaseController<GrainsituationRecordDetail>
{
    @Autowired
    private IGrainsituationRecordDetailService grainsituationRecordDetailService;

    /**
     * 查询粮情主下的详情列表-分页
     */
    @ApiOperation(value = "查询粮情主下的详情列表-分页")
    @PreAuthorize("@ss.hasPermi('web:detail:page')")
    @GetMapping("/page")
    public Result<List<GrainsituationRecordDetail>> page(GrainsituationRecordDetail grainsituationRecordDetail)
    {
        startPage();
        List<GrainsituationRecordDetail> list = grainsituationRecordDetailService.selectGrainsituationRecordDetailList(grainsituationRecordDetail);
        return getPageTable(list);
    }

    /**
     * 查询粮情主下的详情列表
     */
    @ApiOperation(value = "查询粮情主下的详情列表")
    @PreAuthorize("@ss.hasPermi('web:detail:list')")
    @GetMapping("/list")
    public Result<List<GrainsituationRecordDetail>> list(GrainsituationRecordDetail grainsituationRecordDetail)
    {
        List<GrainsituationRecordDetail> list = grainsituationRecordDetailService.selectGrainsituationRecordDetailList(grainsituationRecordDetail);
        return Result.ok(list);
    }

    /**
     * 导出粮情主下的详情列表
     */
    @ApiOperation(value = "导出粮情主下的详情列表")
    @PreAuthorize("@ss.hasPermi('web:detail:export')")
    @Log(title = "粮情主下的详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrainsituationRecordDetail grainsituationRecordDetail)
    {
        List<GrainsituationRecordDetail> list = grainsituationRecordDetailService.selectGrainsituationRecordDetailList(grainsituationRecordDetail);
        ExcelUtil<GrainsituationRecordDetail> util = new ExcelUtil<GrainsituationRecordDetail>(GrainsituationRecordDetail.class);
        util.exportExcel(response, list, "粮情主下的详情数据");
    }

    /**
     * 获取粮情主下的详情详细信息
     */
    @ApiOperation(value = "获取粮情主下的详情详细信息")
    @PreAuthorize("@ss.hasPermi('web:detail:query')")
    @GetMapping(value = "/{id}")
    public Result<GrainsituationRecordDetail> getInfo(@PathVariable("id") Long id)
    {
        return Result.ok(grainsituationRecordDetailService.selectGrainsituationRecordDetailById(id));
    }

    /**
     * 新增粮情主下的详情
     */
    @ApiOperation(value = "新增粮情主下的详情")
    @PreAuthorize("@ss.hasPermi('web:detail:add')")
    @Log(title = "粮情主下的详情", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody GrainsituationRecordDetail grainsituationRecordDetail)
    {
        return Result.ok(grainsituationRecordDetailService.insertGrainsituationRecordDetail(grainsituationRecordDetail));
    }

    /**
     * 修改粮情主下的详情
     */
    @ApiOperation(value = "修改粮情主下的详情")
    @PreAuthorize("@ss.hasPermi('web:detail:edit')")
    @Log(title = "粮情主下的详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody GrainsituationRecordDetail grainsituationRecordDetail)
    {
        return Result.ok(grainsituationRecordDetailService.updateGrainsituationRecordDetail(grainsituationRecordDetail));
    }

    /**
     * 删除粮情主下的详情
     */
    @ApiOperation(value = "删除粮情主下的详情")
    @PreAuthorize("@ss.hasPermi('web:detail:remove')")
    @Log(title = "粮情主下的详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return Result.ok(grainsituationRecordDetailService.deleteGrainsituationRecordDetailByIds(ids));
    }

    @ApiOperation(value = "获取仓房粮情详情")
    @GetMapping("/getRecordDetailList")
    public Result<SectorDTO> getRecordDetailList(GrainsituationRecordDetail grainsituationRecordDetail) {
        return Result.ok(grainsituationRecordDetailService.getRecordDetailList(grainsituationRecordDetail));
    }

}
